package org.dea.mapping;

import java.beans.IntrospectionException;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Set;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class EasyAcceptMappingWriterTest extends TestCase{
	Map<String,DistributedComponent> components;
	String file = "test/xml/mapping.xml";
	String fileClone = "test/xml/mappingClone.xml";

	@Before
	public void setUp() throws Exception {
		components = EasyAcceptMappingReader.processMappingFile("test/xml/mapping.xml");
		new File( fileClone ).delete();
	}

	@After
	public void tearDown() throws Exception {
		new File( fileClone ).delete();
	}

	@Test
	public void testWriteMappingFile() throws IOException, IntrospectionException {
		EasyAcceptMappingWriter.writeMappingFile(components, fileClone);
		Map<String,DistributedComponent> componentsClone = EasyAcceptMappingReader.processMappingFile("test/xml/mappingClone.xml");
		Set<String> keys = componentsClone.keySet();
		for (String string : keys) {
			DistributedComponent component = components.get(string);
			DistributedComponent componentClone = componentsClone.get(string);
			assertEquals(component.getFacade(), componentClone.getFacade());
			assertEquals(component.getHostAddress(), componentClone.getHostAddress());
			assertEquals(component.getHostLabel(), componentClone.getHostLabel());
			assertEquals(component.getHostPort(), componentClone.getHostPort());
		}
	}

}
